<<<<<<< .mine
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tasks;


//import java.io.IOException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Matrix
 */
public class Tests {
    public static void test() {
                
        //**********TESTS****************
        System.out.println("Boo");
        TaskManageSubsystem root = new TaskManageSubsystem(0);
        int threadQ = new Random().nextInt(1000) + 1;
        root.createProcess(1, true, threadQ);
        int k = 2200;//new Random().nextInt(10000) + 1;
        System.out.println("To Create:" + (k+1));
        for (int i = 0; i < k; i++) {
            root.createProcess(root.getProcessList().getNext().getCurrent().getId(), false, threadQ);
            ProcessDesc temp = root.getProcessList().getNext();
            for (int j = 0; j < 5; j++) { //(new Random().nextInt(10) + 1)
                temp.getCurrent().createThread(root.getNextPid());
            }
        }
        System.out.println(root.returnTasksState()+"\n total processes "+ root.getProcessesQuantity());
        int l = root.getProcessesQuantity();
        
        //Add find test
        Process temp1 = root.getProcessList().getPrev().getCurrent();
        System.out.println("HouHou: "+temp1.find(temp1.getId()+1).getState());
        
        // Global find test
        int temp3 = new Random().nextInt(root.getProcessList().getNext().getCurrent().getId()) + 1; 
        System.out.println("Finding id is: "+temp3);
        try {
            ProcessDesc temp2 = root.find(temp3);
            if (temp2.getCurrent().getId() == temp3) {
                System.out.println("Finded Process"+ temp2.getCurrent().getId());
            } else System.out.println("Finded Thread "+temp2.getCurrent().returnThreadsState());
        } catch (NotFoundException NFE) {
            System.out.println(NFE.getMessage());                        
        }
        
        // Save/load test
        try {
            TaskManageSubsystem.hibernate(root, "1.tmp");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try {
            root = TaskManageSubsystem.unhibernate("1.tmp");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        // Killing test
        k = new Random().nextInt(10000) + 1;
        System.out.println("To Kill:" + k);
        for (int i = 0; i < k; i++) {
            try {
                System.out.println(i+" try to kill threads");
                ProcessDesc temp = root.getProcessList().getPrev();
                for (int j = 0; j < (new Random().nextInt(10) + 1); j++) {
                    Thread currThread = temp.getCurrent().killThread();
                    System.out.print(currThread.getId()+"-thread killed now; ");
                }
                System.out.println("");
                
            } catch (OneThreadedException OTE) {
                System.out.println("");
                System.out.print(OTE.getMessage());
                System.out.println("; break1-OT");
            } catch (NoProcessesException NPE) {
                System.out.println(NPE.getMessage());
                System.out.println("break2-No Process, No tasks");
            }
            try {
                ProcessDesc temp = root.killProcess(new Random().nextInt(10000) + 1);
                System.out.println(temp.getCurrent().getId()+" - this process killed now");
            } catch (NoProcessesException NPE) {
                System.out.println(NPE.getMessage());
                System.out.println("break3-No process killed");
                break;
            } catch (NotFoundException nFE) {
                System.out.println("break3-No process killed, because process with this pId not found");
            }
        }
        try {
            System.out.println(root.returnTasksState());
        } catch (NoProcessesException NPE) {
            System.out.println(NPE.getMessage());
            System.out.println("Not to display");
            
        }
        System.out.println(l-root.getProcessesQuantity()+" killed");
        System.out.println("Bye!");
        /*try {
            int x = System.in.read();
            System.out.println(x);
        } catch(IOException z) {
            System.out.println("Hey");
        }*/
    }
    
}
=======
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kurs;


//import java.io.IOException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Matrix
 */
public class Tests {
    public static void test() {
                
        //**********TESTS****************
        System.out.println("Boo");
        TaskManageSubsystem root = new TaskManageSubsystem(0);
        int threadQ = new Random().nextInt(1000) + 1;
        root.createProcess(1, true, threadQ);
        int k = 2200;//new Random().nextInt(10000) + 1;
        System.out.println("To Create:" + (k+1));
        for (int i = 0; i < k; i++) {
            root.createProcess(root.getProcessList().getNext().getCurrent().getId(), false, threadQ);
            ProcessDesc temp = root.getProcessList().getNext();
            for (int j = 0; j < 5; j++) { //(new Random().nextInt(10) + 1)
                temp.getCurrent().createThread(root.getNextPid());
            }
        }
        System.out.println(root.returnTasksState()+"\n total processes "+ root.getProcessesQuantity());
        int l = root.getProcessesQuantity();
        
        //Add find test
        Process temp1 = root.getProcessList().getPrev().getCurrent();
        System.out.println("HouHou: "+temp1.find(temp1.getId()+1).getState());
        
        // Global find test
        int temp3 = new Random().nextInt(root.getProcessList().getNext().getCurrent().getId()) + 1; 
        System.out.println("Finding id is: "+temp3);
        try {
            ProcessDesc temp2 = root.find(temp3);
            if (temp2.getCurrent().getId() == temp3) {
                System.out.println("Finded Process"+ temp2.getCurrent().getId());
            } else System.out.println("Finded Thread "+temp2.getCurrent().returnThreadsState());
        } catch (NotFoundException NFE) {
            System.out.println(NFE.getMessage());                        
        }
        
        // Save/load test
        try {
            TaskManageSubsystem.hibernate(root, "1.tmp");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try {
            root = TaskManageSubsystem.unhibernate("1.tmp");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        // Killing test
        k = new Random().nextInt(10000) + 1;
        System.out.println("To Kill:" + k);
        for (int i = 0; i < k; i++) {
            try {
                System.out.println(i+" try to kill threads");
                ProcessDesc temp = root.getProcessList().getPrev();
                for (int j = 0; j < (new Random().nextInt(10) + 1); j++) {
                    Thread currThread = temp.getCurrent().killThread();
                    System.out.print(currThread.getId()+"-thread killed now; ");
                }
                System.out.println("");
                
            } catch (OneThreadedException OTE) {
                System.out.println("");
                System.out.print(OTE.getMessage());
                System.out.println("; break1-OT");
            } catch (NoProcessesException NPE) {
                System.out.println(NPE.getMessage());
                System.out.println("break2-No Process, No tasks");
            }
            try {
                ProcessDesc temp = root.killProcess(new Random().nextInt(10000) + 1);
                System.out.println(temp.getCurrent().getId()+" - this process killed now");
            } catch (NoProcessesException NPE) {
                System.out.println(NPE.getMessage());
                System.out.println("break3-No process killed");
                break;
            } catch (NotFoundException nFE) {
                System.out.println("break3-No process killed, because process with this pId not found");
            }
        }
        try {
            System.out.println(root.returnTasksState());
        } catch (NoProcessesException NPE) {
            System.out.println(NPE.getMessage());
            System.out.println("Not to display");
            
        }
        System.out.println(l-root.getProcessesQuantity()+" killed");
        System.out.println("Bye!");
        /*try {
            int x = System.in.read();
            System.out.println(x);
        } catch(IOException z) {
            System.out.println("Hey");
        }*/
    }
    
}
>>>>>>> .r60
